package com.lanxiao.cloud.modules.gateway.route.application;

import com.lanxiao.cloud.modules.gateway.route.application.assembler.GatewayRouteAssembler;
import com.lanxiao.cloud.modules.gateway.route.application.dto.GatewayRouteCmdAdd;
import com.lanxiao.cloud.modules.gateway.route.application.dto.GatewayRouteCmdUpdate;
import com.lanxiao.cloud.modules.gateway.route.domain.model.GatewayRoute;
import com.lanxiao.cloud.modules.gateway.route.domain.service.IGatewayRouteService;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2021-09-09
 */
@Component
public class GatewayRouteCmdManager {

  private final IGatewayRouteService gatewayRouteService;
  private final GatewayRouteAssembler gatewayRouteAssembler;

  public GatewayRouteCmdManager(
      IGatewayRouteService gatewayRouteService,
      GatewayRouteAssembler gatewayRouteAssembler) {
    this.gatewayRouteService = gatewayRouteService;
    this.gatewayRouteAssembler = gatewayRouteAssembler;
  }

  /**
   *  新增路由信息
   *  推送消息，重置网关路由信息
   * @author ：qiaoliang
   * @param commandAdd : 路由新增请求模型
   * @date 2021-08-20 15:25
   */
  public void save(GatewayRouteCmdAdd commandAdd){
    gatewayRouteService.saveRoute(gatewayRouteAssembler.toGatewayRoute(commandAdd));
  }

  /***
   *  修改路由信息
   *  推送消息，重置网关路由信息
   * @author ：qiaoliang
   * @param id : 主键
   * @param commandUpdate : 路由修改请求模型
   * @date 2021-08-20 15:26
   */
  public void update(Long id, GatewayRouteCmdUpdate commandUpdate){
    final GatewayRoute gatewayRoute = gatewayRouteAssembler.toGatewayRoute(commandUpdate);
    gatewayRoute.setId(id);
    gatewayRouteService.updateByIdRoute(gatewayRoute);
  }

  /**
   *  删除路由信息
   *  推送消息，重置网关路由信息
   *
   * @author ：qiaoliang
   * @param id : 主键
   * @date 2021-08-20 15:31
   */
  public void delete(Long id){
    gatewayRouteService.deleteByIdRoute(id);
  }

}
